package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author XIN
 * 2023/4/16
 */
@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {

	@Autowired
	private BaseAttrInfoService baseAttrInfoService;
	
	/**
	 * 根据多个 三级分类ID 查询当前分类包含平台属性名列表
	 * @param category1Id
	 * @param category2Id
	 * @param category3Id
	 * @return
	 */
	@GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
	public Result attrInfoList(@PathVariable Long category1Id,
	                           @PathVariable Long category2Id,
	                           @PathVariable Long category3Id) {
		List<BaseAttrInfo> baseAttrInfos =baseAttrInfoService.attrInfoList(category1Id,category2Id,category3Id);
		
		return Result.ok(baseAttrInfos);
	}
	
	@PostMapping("/saveAttrInfo")
	public Result saveAttrInfo(@RequestBody BaseAttrInfo base) {
		baseAttrInfoService.saveAttrInfo(base);
		
		return Result.ok();
	}
	
	@GetMapping("/getAttrValueList/{attrId}")
	public Result getAttrValueList(@PathVariable Long attrId) {
		List<BaseAttrValue> baseAttrValues = baseAttrInfoService.getAttrValueList(attrId);
		return Result.ok(baseAttrValues);
	}
}
